package net.uworks.apps.bluelcdfontconverter;

import java.io.*;

/**
 * <p>Title: BlueLCD Font Converter</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: uWorks</p>
 *
 * @author Josep del Rio
 * @version 1.0
 */
public class StandardFontCreator {
    final private static byte[] NULL_CHAR = { 0,0,0,0,0,0,0,0 };

    final private static byte[][] CHARS_16_31 = {
                                                { 16,16,16,16,16,16,16,0},
                                                { 24,24,24,24,24,24,24,0},
                                                { 28,28,28,28,28,28,28,0},
                                                {30,30,30,30,30,30,30,0},
                                                {31,31,31,31,31,31,31,0},
                                                {15,15,15,15,15,15,15,0},
                                                {7,7,7,7,7,7,7,0},
                                                {3,3,3,3,3,3,3,0},
                                                {1,1,1,1,1,1,1,0},
                                                {4,6,5,5,13,28,24,0},
                                                {24,24,0,7,8,8,7,0},
                                                {24,24,0,15,8,14,8,0},
                                                {0,0,31,14,4,0,0,0},
                                                {0,8,12,14,12,8,0,0},
                                                {0,2,6,14,6,2,0,0},
                                                {0,0,4,14,31,0,0,0}
    };

    final private static byte[][] CHARS_33_127 = { { 4,4,4,4,0,0,4,0 },
                                                 { 10,10,10,0,0,0,0,0 },
                                                 { 10,10,31,10,31,10,10,0 },
                                                 { 4,15,20,14,5,30,4,0 },
                                                 { 24,25,2,4,8,19,3,0 },
                                                 { 12,18,20,8,21,18,13,0 },
                                                 { 12,4,8,0,0,0,0,0 },
                                                 { 2,4,8,8,8,4,2,0 },
                                                 { 8,4,2,2,2,4,8,0 },
                                                 { 0,4,21,14,21,4,0,0 },
                                                 { 0,4,4,31,4,4,0,0 },
                                                 { 0,0,0,0,12,4,8,0 },
                                                 { 0,0,0,31,0,0,0,0 },
                                                 { 0,0,0,0,0,12,12,0 },
                                                 { 0,1,2,4,8,16,0,0 },
                                                 { 14,17,19,21,25,17,14,0 },
                                                 { 4,12,4,4,4,4,14,0 },
                                                 { 14,17,1,2,4,8,31,0 },
                                                 { 31,2,4,2,1,17,14,0 },
                                                 { 2,6,10,18,31,2,2,0 },
                                                 { 31,16,30,1,1,17,14,0 },
                                                 { 6,8,16,30,17,17,14,0 },
                                                 { 31,1,2,4,8,8,8,0 },
                                                 { 14,17,17,14,17,17,14,0 },
                                                 { 14,17,17,15,1,2,12,0 },
                                                 { 0,12,12,0,12,12,0,0 },
                                                 { 0,12,12,0,12,4,8,0 },
                                                 { 2,4,8,16,8,4,2,0 },
                                                 { 0,0,31,0,31,0,0,0 },
                                                 { 8,4,2,1,2,4,8,0 },
                                                 { 14,17,1,2,4,0,4,0 },
                                                 { 14,17,1,13,21,21,14,0 },
                                                 { 14,17,17,17,31,17,17,0 },
                                                 { 30,17,17,30,17,17,30,0 },
                                                 { 14,17,16,16,16,17,14,0},
                                                 { 28,18,17,17,17,18,28,0 },
                                                 { 31,16,16,30,16,16,31,0 },
                                                 { 31,16,16,30,16,16,16,0 },
                                                 { 14,17,16,23,17,17,15,0 },
                                                 { 17,17,17,31,17,17,17,0 },
                                                 { 14,4,4,4,4,4,14,0 },
                                                 { 7,2,2,2,2,18,12,0 },
                                                 { 17,18,20,24,20,18,17,0 },
                                                 { 16,16,16,16,16,16,31,0 },
                                                 { 17,27,21,21,17,17,16,0},
                                                 { 17,17,25,21,19,17,17,0 },
                                                 { 14,17,17,17,17,17,14,0 },
                                                 { 30,17,17,30,16,16,16,0 },
                                                 { 14,17,17,17,21,18,13,0 },
                                                 { 30,17,17,30,20,18,17,0 },
                                                 { 15,16,16,14,1,1,30,0 },
                                                 { 31,4,4,4,4,4,4,0 },
                                                 { 17,17,17,17,17,17,14,0 },
                                                 { 17,17,17,17,17,10,4,0 },
                                                 { 17,17,17,21,21,21,10,0 },
                                                 { 17,17,10,4,10,17,17,0 },
                                                 { 17,17,17,10,4,4,4,0 },
                                                 { 31,1,2,4,8,16,31,0 },
                                                 { 14,8,8,8,8,8,14,0 },
                                                 { 17,10,31,4,31,4,4,0 },
                                                 { 14,2,2,2,2,2,14,0 },
                                                 { 4,10,17,0,0,0,0,0 },
                                                 { 0,0,0,0,0,0,31,0 },
                                                 { 8,4,2,0,0,0,0,0 },
                                                 { 0,0,14,1,15,17,15,0 },
                                                 { 16,16,16,22,25,17,30,0 },
                                                 { 0,0,14,16,16,17,14,0 },
                                                 { 1,1,1,13,19,17,15,0 },
                                                 { 0,0,14,17,31,16,14,0 },
                                                 { 6,9,8,28,8,8,8,0 },
                                                 { 0,15,17,17,15,1,14,0 },
                                                 { 16,16,22,25,17,17,17,0 },
                                                 { 0,4,0,12,4,4,14,0 },
                                                 { 2,0,6,2,2,18,12,0 },
                                                 { 8,8,9,10,12,10,9,0 },
                                                 { 12,4,4,4,4,4,14,0 },
                                                 { 0,0,26,21,21,17,17,0 },
                                                 { 0,0,22,25,17,17,17,0 },
                                                 { 0,0,14,17,17,17,14,0 },
                                                 { 0,0,30,17,30,16,16,0 },
                                                 { 0,0,13,19,15,1,1,0 },
                                                 { 0,0,22,25,16,16,16,0 },
                                                 { 0,0,14,16,14,1,30,0 },
                                                 { 8,8,28,8,8,9,6,0 },
                                                 { 0,0,17,17,17,19,13,0 },
                                                 { 0,0,17,17,17,10,4,0 },
                                                 { 0,0,17,17,21,21,10,0 },
                                                 { 0,0,17,10,4,10,17,0 },
                                                 { 0,0,17,17,15,1,14,0 },
                                                 { 0,0,31,2,4,8,31,0 },
                                                 { 2,4,4,8,4,4,2,0 },
                                                 { 4,4,4,4,4,4,4,0 },
                                                 { 8,4,4,2,4,4,8,0 },
                                                 { 0,4,2,31,2,4,0,0 },
                                                 { 0,4,8,31,8,4,0,0 }};

    final private static byte[][] CHARS_128_159 = {
                                                  {10,0,4,10,17,31,17,0},
                                                  {0,0,4,10,17,31,17,0},
                                                  {4,10,4,10,17,31,17,0},
                                                  {2,4,14,1,15,17,15,0},
                                                  {4,0,14,1,15,17,15,0},
                                                  {31,24,24,31,24,24,31,0},
                                                  {17,14,17,17,17,17,14,0},
                                                  {0,10,0,14,17,17,14,0},
                                                  {1,14,19,21,25,14,16,0},
                                                  {0,2,14,21,21,14,8,0},
                                                  {17,0,17,17,17,17,14,0},
                                                  {0,10,0,17,17,19,13,0},
                                                  {0,16,8,4,2,1,0,0},
                                                  {1,2,31,4,31,8,16,0},
                                                  {0,8,21,21,2,0,0,0},
                                                  {15,16,14,17,14,1,30,0},
                                                  {15,20,20,31,20,20,20,0},
                                                  {0,0,26,5,31,20,11,0},
                                                  {6,9,8,28,8,8,31,0},
                                                  {28,18,28,18,23,18,19,0},
                                                  {0,14,31,31,31,14,0,0},
                                                  {0,14,17,17,17,14,0,0},
                                                  {0,4,14,31,14,4,0,0},
                                                  {0,4,10,17,10,4,0,0},
                                                  {4,4,4,0,4,4,4,0},
                                                  {15,16,16,16,15,4,8,0},
                                                  {0,1,3,5,9,17,31,0},
                                                  {2,4,8,4,2,0,31,0},
                                                  {8,4,2,4,8,0,31,0},
                                                  {1,1,5,9,31,8,4,0},
                                                  {4,14,21,4,4,4,4,0},
                                                  {4,4,4,4,21,14,4,0},

    };

    final private static byte[][] CHARS_161_255 = { { 0,0,0,0,28,20,28,0 },
                                                  { 7,4,4,4,0,0,0,0 },
                                                  { 0,0,0,4,4,4,28,0 },
                                                  {0,0,0,0,16,8,4,0},
                                                  {0,0,0,12,12,0,0,0},
                                                  {0,31,1,31,1,2,4,0},
                                                  {0,0,31,1,6,4,8,0},
                                                  {0,0,2,4,12,20,4,0},
                                                  {0,0,4,31,17,1,6,0},
                                                  {0,0,0,31,4,4,31,0},
                                                  {0,0,2,31,6,10,18,0},
                                                  {0,0,8,31,9,10,8,0},
                                                  {0,0,0,14,2,2,31,0},
                                                  {0,0,30,2,30,2,30,0},
                                                  {0,0,0,21,21,1,6,0},
                                                  {0,0,0,31,0,0,0,0},
                                                  {31,1,5,6,4,4,8,0},
                                                  {1,2,4,12,20,4,4,0},
                                                  {4,31,17,17,1,2,4,0},
                                                  {0,31,4,4,4,4,31,0},
                                                  {2,31,2,6,10,18,2,0},
                                                  {8,31,9,9,9,9,18,0},
                                                  {4,31,4,31,4,4,4,0},
                                                  {0,15,9,17,1,2,12,0},
                                                  {8,15,18,2,2,2,4,0},
                                                  {0,31,1,1,1,1,31,0},
                                                  {10,31,10,10,2,4,8,0},
                                                  {0,24,1,25,1,2,28,0},
                                                  {0,31,1,2,4,10,17,0},
                                                  {8,31,9,10,8,8,7,0},
                                                  {0,17,17,9,1,2,12,0},
                                                  {0,15,9,25,3,2,12,0},
                                                  {2, 28,4,31,4,4,8,0},
                                                  {0,21,21,21,1,2,4,0},
                                                  {14,0,31,4,4,4,8,0},
                                                  {8,8,8,12,10,8,8,0},
                                                  {4,4,31,4,4,8,16,0},
                                                  {0,14,0,0,0,0,31,0},
                                                  {0,31,1,10,4,10,16,0},
                                                  {4,31,2,4,14,21,4,0},
                                                  {2,2,2,2,2,4,8,0},
                                                  {0,4,2,17,17,17,17,0},
                                                  {16,16,31,16,16,16,15,0},
                                                  {0,31,1,1,1,2,12,0},
                                                  {0,8,20,2,1,1,0,0},
                                                  {4,31,4,4,21,21,4,0},
                                                  {0,31,1,1,10,4,2,0},
                                                  {0,14,0,14,0,14,0,0},
                                                  {0,4,8,16,17,31,1,0},
                                                  {0,1,1,10,4,10,16,0},
                                                  {0,31,8,31,8,8,7,0},
                                                  {8,8,31,9,10,8,8,0},
                                                  {0,14,2,2,2,2,31,0},
                                                  {0,31,1,31,1,1,31,0},
                                                  {14,0,31,1,1,2,4,0},
                                                  {18,18,18,18,2,4,8,0},
                                                  {0,4,20,20,21,21,22,0},
                                                  {0,16,16,17,18,20,24,0},
                                                  {0,31,17,17,17,17,31,0},
                                                  {0,31,17,17,1,2,4,0},
                                                  {0,24,0,1,1,2,28,0},
                                                  {4,18,8,0,0,0,0,0},
                                                  {28,20,28,0,0,0,0,0},
                                                  {0,0,9,21,18,18,13,0},
                                                  {10,0,14,1,15,17,15,0},
                                                  {0,14,17,30,17,30,16,0},
                                                  {0,0,14,16,12,17,14,0},
                                                  {0,17,17,19,29,16,16,0},
                                                  {0,0,15,20,18,17,14,0},
                                                  {0,6,9,17,30,16,16,0},
                                                  {0,0,15,17,15,1,14,0},
                                                  {0,0,7,4,4,20,8,0},
                                                  {2,26,2,0,0,0,0,0},
                                                  {0,2,0,2,2,18,12,0},
                                                  {20,8,20,0,0,0,0,0},
                                                  {0,4,14,20,21,14,4,0},
                                                  {8,8,28,8,28,8,15,0},
                                                  {14,0,22,25,17,17,17,0},
                                                  {10,0,14,17,17,17,14,0},
                                                  {0,22,25,17,30,16,16,0},
                                                  {0,13,19,17,15,1,1,0},
                                                  {0,14,17,31,17,17,14,0},
                                                  {0,0,0,11,21,26,0,0},
                                                  {0,0,14,17,17,10,27,0},
                                                  {10,0,17,17,17,19,13,0},
                                                  {31,16,8,4,8,16,31,0},
                                                  {0,0,31,10,10,10,19,0},
                                                  {31,0,17,10,4,10,17,0},
                                                  {0,0,17,17,15,1,14,0},
                                                  {0,1,30,4,31,4,4,0},
                                                  {0,0,31,8,15,9,17,0},
                                                  {0,0,31,21,31,17,17,0},
                                                  {0,4,0,31,0,4,0,0},
                                                  NULL_CHAR,
                                                  {31,31,31,31,31,31,31,0}
    };

    public static void main(String[] args) {
        try {
            File targetFile = new File("result.fnt");
            FileOutputStream out = new FileOutputStream(targetFile, false);

            for (int c=0; c<256; c++) {
                if ((c >= 16) && (c <= 31)) {
                    out.write(CHARS_16_31[c-16]);
                } else if ((c >= 33) && (c<=127)) {
                    out.write(CHARS_33_127[c-33]);
                } else if (( c >= 128) && (c<= 159)) {
                    out.write(CHARS_128_159[c-128]);
                } else if ((c >=161) && (c<= 255)) {
                    out.write(CHARS_161_255[c-161]);
                } else {
                    out.write(NULL_CHAR);
                }
            }
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
